<template>
  <el-row>
    <el-col :span="12" class="logon-box">
      <el-col :span="12">
        <img src="../../public/img/icons/logon.png" alt="">
      </el-col>
      <el-col :span="12">
        <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
          <el-form-item label="用户名" prop="username">
            <el-input v-model="form.username" autocomplete="off" />
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="form.password" autocomplete="off" />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="logOn">登录</el-button>
          </el-form-item>
        </el-form>

      </el-col>
    </el-col>
  </el-row>
</template>
<style scoped lang="scss">
.logon-box {
  height: 700px;
  background-color: red;
}

.logon-box img {
  width: 100%;
  height: 700px;

}
</style>
<script>
import axios from 'axios'
export default {
  data() {
    return {
      form: {
        username: '',
        password: ''
      },
      baseURL: 'http://43.138.15.137:7000/api/private/v1'
    }
  },
  methods: {
    logOn() {
      axios.post(this.baseURL + '/login', this.form).then(res => {
        let { data: { data, meta } } = res
        if (meta.status === 200) {
          this.$message({
            message: '登录成功',
            type: 'success'
          })
          localStorage.setItem('token', data.token)
          this.$router.push({
            path: '/list'
          })
        } else {
          this.$message({
            message: meta.msg,

            type: 'error'
          })
          return
        }
      })
    }
  }
}
</script>
